from rich.console import Console
from rich.logging import RichHandler
import logging

# 配置日志
logging.basicConfig(
    level="DEBUG",
    format="%(message)s",
    datefmt="[%X]",
    handlers=[RichHandler(rich_tracebacks=True)]
)

logger = logging.getLogger("rich_logger")

# 自定义主题
logger.addHandler(RichHandler(
    theme={
        "logging.level.debug": "dim gray",
        "logging.level.info": "cyan",
        "logging.level.warning": "yellow",
        "logging.level.error": "bold red",
        "logging.level.critical": "bold red on black"
    }
))

# 测试日志
logger.debug("这是一条调试信息")
logger.info("常规操作记录")
logger.warning("潜在问题警告")
logger.error("发生错误！")
logger.critical("严重系统故障")